package com.technology.education.ui.student.message

import androidx.lifecycle.MutableLiveData
import com.technology.education.data.model.MessageListModel
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

class MessageViewModel : BaseViewModel() {
    val result = MutableLiveData<ResultState<MessageListModel>>()
    val delResult = MutableLiveData<String>()
    val readResult = MutableLiveData<String>()
    override fun getData() {
        super.getData()
        request({
            apiService.messageList(
                hashMapOf(
                    "pageNo" to pageIndex,
                    "pageSize" to pageSize
                )
            )
        }, result)
    }

    fun delMessage(id: String) {
        request(
            { apiService.delMsg(hashMapOf("ids" to id)) },
            success = {
                delResult.postValue(id)
            },
            error = { toast(it.errorMsg) })
    }

    fun readMessage(id: String) {
        request(
            { apiService.viewMsg(hashMapOf("ids" to id)) },
            success = {
                readResult.postValue(id)
            },
            error = { toast(it.errorMsg) })
    }
}